<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <!--ckeditor-->
    <script src="/js/plugins/ckeditor/ckeditor.js"></script>

    <script type="text/javascript">
        $(function(){
            $("#pagination").twbsPagination({
                totalPages:${pageInfo.pages}||1,
                visiblePages:5,
                startPage:${qo.currentPage},
                first:"首页",
                prev:"上一页",
                next:"下一页",
                last:"尾页",
                onPageClick:function(event,page){
                    $("#currentPage").val(page);
                    $("#searchForm").submit();
                }
            });

            $("#query").click(function(){
                $("#currentPage").val(1);
                $("#searchForm").submit();
            });



            // 使用jQueryform修改模态框的提交方式-ajax方式,在表单提交之前
            $('#editForm').ajaxForm(function (data) {
                if (data.success) {
                    // 操作成功,刷新页面
                    location.reload();
                } else {
                    alert(data.msg);
                }
            });

            //初始化ckeditor
            var ck = CKEDITOR.replace( 'editor1' );

            //模态框的表单提交
            $("#saveBtn").click(function() {
                //获取编辑器中的内容,设置到textarea里面
                var data = ck.getData();
                $("#editor1").html(data);
                //提交表单
                $("#editForm").submit();
            });


            $(".inputBtn").click(function () {
                //1:先清空模态框的数据,再来做操作
                $('#inputModal input').val('');
                $('#inputModal select').val('');
                $('#inputModal img').attr('src','');
                //2:获取当前按钮中的自定义JSON对象
                var obj = $(this).data("json");
                console.log(obj);
                //3:只有编辑按钮才做数据回显
                if (obj) {
                    $("#inputModal input[name='id']").val(obj.id);
                    $("#inputModal input[name='title']").val(obj.title);
                    $("#inputModal select[name='state']").val(obj.state);
                    $("#inputModal input[name='coverUrl']").val(obj.coverUrl);
                    $("#inputModal input[name='sequence']").val(obj.sequence);
                    $("#coverImg").attr('src',obj.coverUrl);

                    //回显攻略下拉框
                    $("#strategySelect").val(obj.strategyId);

                    //根据攻略id获取所有的攻略分类
                    $.get('/strategyCatalog/listByStrategyId.do',{strategyId:obj.strategyId},function (data) {
                        var temp  = "";
                        $.each(data,function (index, ele) {
                            temp += '<option value="'+ele.id+'">'+ele.name+'</option>';
                        })
                        $("#catalogSelect").html(temp);
                        //回显分类下拉框
                        $("#catalogSelect").val(obj.catalogId);
                    })

                    //回显攻略文章内容
                    $.get('/strategyDetail/getContentById.do',{id:obj.id},function(data){
                        ck.setData(data.content);
                    })


                }
                $("#inputModal").modal('show');
            })

            //攻略下拉框
            $("#strategySelect").change(function () {
                //获取当前选择的攻略的id
                var strategyId = $(this).val();
                //根据攻略id获取所有的攻略分类
                $.get('/strategyCatalog/listByStrategyId.do',{strategyId:strategyId},function (data) {
                    var temp  = "";
                    $.each(data,function (index, ele) {
                        temp += '<option value="'+ele.id+'">'+ele.name+'</option>';
                    })
                    $("#catalogSelect").html(temp);
                })

            })

        });

    </script>
</head>

<body>

<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#assign currentMenu = "strategyDetail" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>攻略管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyDetail/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" name="keyword" value="${(qo.keyword)!''}" placeholder="请输入标题关键字">
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <a href="javascript:" class="btn btn-success inputBtn">添加攻略</a>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>标题</th>
                        <th>封面</th>
                        <th>发布时间</th>
                        <th>排序</th>
                        <th>攻略类别</th>
                        <th>状态</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
					<#list pageInfo.list as vo>
                    <tr>
                        <td>${vo.title}</td>
                        <td><img src='${vo.coverUrl!""}' width="100px"/> </td>
                        <td>${(vo.releaseTime?string('y-M-d'))!}</td>
                        <td>${vo.sequence}</td>
                        <td>${vo.catalog.name}</td>
                        <td>
                            <#if vo.state == 1>
                                草稿
                            <#elseif vo.state == 0>
                                发布
                            </#if>
                        </td>
                        <td>
                            <a href="javascript:" class="btn btn-sm btn-success inputBtn" data-json='${vo.json}'>
                                <span class="glyphicon glyphicon-edit"></span> 修改
                            </a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/strategyDetail/saveOrUpdate.do" enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control"name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面</label>
                        <div class="col-sm-7">
                            <img id="coverUrl" width="100%"/>
                            <input type="file" class="form-control" name="file" >
                            <input type="hidden" name="coverUrl" ><#--传后台-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-3 control-label">所属攻略：</label>
                        <div class="col-lg-7">
                            <select class="form-control" id="strategySelect">
                                <#list strategies as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-3 control-label">攻略类别：</label>
                        <div class="col-lg-7">
                            <select class="form-control"  id="catalogSelect" name="catalog.id">
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">排序</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="sequence">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态</label>
                        <div class="col-sm-7">
                            <select id="state" class="form-control" autocomplete="off" name="state" >
                                <option value="0">草稿</option>
                                <option value="1">发布</option>
                            </select>
                        </div>
                    </div>
                    <textarea name="strategyContent.content" id="editor1" ></textarea>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

</body>
</html>